/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.tyust.lawyermanager.dongao.controller;

import com.tyust.lawyermanager.dongao.entity.Lawyer;
import com.tyust.lawyermanager.dongao.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlReturnUpdateCount;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 律师控制器
 * @author licaixia
 * @version 1.0
 * @date 2023/1/4
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    @RequestMapping("/modify")
    public String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
        //return "../static/success";
        //跳转到其他的controller中
        return "redirect:/show";
    }

    @RequestMapping("/get")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyerById(lawyerid);
        // 把查询得到的lawyer对象保存起来，传递到网页上
        model.addAttribute("lawyer", lawyer);
        return "../static/modifyLawyer";
    }

    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
        lawyerService.removeLawyer(lawyerid);

        return "../static/success";
    }
    @RequestMapping("/show")
    public String showLawyer(Model model){

        List<Lawyer> lawyerList = lawyerService.findLawyer();
        //将lawyerList传递到网页上，将lawyerList集合保存
        model.addAttribute("lawList",lawyerList);
//        加入路径，就不会报错（500）
        return "../static/displayLawyer";
    }


    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        //success代表网页
        //return "success.html";
        return "../static/success";
        //RequestMapping-映射，括号中为映射的路径，不可用汉字
    }
}

